package com.servlet;

import com.dao.EmployeeDao;
import com.model.Employee;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/updateEmp")
public class EmpUpdateServlet extends HttpServlet {
    private EmployeeDao employeeDao = new EmployeeDao();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");

        String id = req.getParameter("id");
        String name = req.getParameter("empName");
        String gender = req.getParameter("empGender");
        String salary = req.getParameter("empSalary");
        Employee employee = new Employee(Integer.parseInt(id), name, gender, "1", Double.parseDouble(salary));
        int rows = employeeDao.updateById(employee);
        if (rows > 0) {
            req.setAttribute("msg", "宿舍修改成功");
        } else {
            req.setAttribute("msg", "宿舍修改失败");
        }
        req.getRequestDispatcher("msg.jsp").forward(req, resp);


    }
}
